package treeMap;

import java.util.Map;
import java.util.TreeMap;

public class TreeMapTest2 {
    public static void main(String[] args) {


        //统计字符串中每个字符出现的次数
        String s="ewqeqweqwr";

        Map<Character,Integer>mp=new TreeMap<>();
        for (int i = 0; i < s.length(); i++) {
            char charAt = s.charAt(i);
            //判断是否存在
            if (mp.containsKey(charAt)){
                //获得当前的count
                Integer count = mp.get(charAt);
                count++;
                mp.put(charAt,count);
            }else {
                mp.put(charAt,1);
            }
        }
        StringBuilder sb=new StringBuilder();
        mp.forEach((key,value)->sb.append(key).append("(").append(value).append(")"));
        System.out.println(sb);
    }
}
